﻿using Code;
using FluorineFx.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Parse
{
    class Program:ParseCode
    {

        private static string jsonStr="{\"Name\":\"一级节点\",\"Children\":[{\"Name\":\"N级节点\",\"Children\":[{\"Name\":\"沐光\",\"PassWord\":\"E10ADC3949BA59ABBE56E057F20F883E\",\"Age\":25,\"CreateTime\":\"2016-02-22T10:56:44\",\"IsEnd\":true}]}]}";

        private static string JavaScriptJson = "{\"Name\":\"一级节点\",\"PassWord\":null,\"Age\":null,\"CreateTime\":null,\"Children\":[{\"Name\":\"N级节点\",\"PassWord\":null,\"Age\":null,\"CreateTime\":null,\"Children\":[{\"Name\":\"沐光\",\"PassWord\":\"E10ADC3949BA59ABBE56E057F20F883E\",\"Age\":25,\"CreateTime\":\"\\/Date(1456112249273)\\/\",\"Children\":null,\"IsEnd\":true}],\"IsEnd\":null}],\"IsEnd\":null}";

        private static string AMF3Base64 = "CgsBCU5hbWUGGeS4gOe6p+iKgueCuRFDaGlsZHJlbgkDAQoLAQAGFU7nuqfoioLngrkECQMBCgsBAAYN5rKQ5YWJB0FnZQQZEVBhc3NXb3JkBkFFMTBBREMzOTQ5QkE1OUFCQkU1NkUwNTdGMjBGODgzRRVDcmVhdGVUaW1lBicyMDE2LTAyLTIyVDEwOjI1OjM1C0lzRW5kAwEBAQ==";
        private static string AMF3Base64Model = "CmMlQ29kZS5DaGlsZHJlbk1vZGVsCU5hbWURUGFzc1dvcmQHQWdlFUNyZWF0ZVRpbWURQ2hpbGRyZW4LSXNFbmQGGeS4gOe6p+iKgueCuQEBAQkDAQoBBhVO57qn6IqC54K5AQEBCQMBCgEGDeaykOWFiQZBRTEwQURDMzk0OUJBNTlBQkJFNTZFMDU3RjIwRjg4M0UEGQgBQnUxzYIKkAABAwEB";

        private static string BFBase64 = "AAEAAAD/////AQAAAAAAAAAEAQAAAOIBU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWMuRGljdGlvbm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c3YTVjNTYxOTM0ZTA4OV1dAgAAAAYDAAAADOS4gOe6p+iKgueCuQoKCgkEAAAACgQEAAAAdFN5c3RlbS5Db2xsZWN0aW9ucy5HZW5lcmljLkxpc3RgMVtbQ29kZS5DaGlsZHJlbk1vZGVsLCBDb2RlLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbF1dAwAAAAZfaXRlbXMFX3NpemUIX3ZlcnNpb24EAAAUQ29kZS5DaGlsZHJlbk1vZGVsW10CAAAACAgJBQAAAAEAAAABAAAABwUAAAAAAQAAAAQAAAAEEkNvZGUuQ2hpbGRyZW5Nb2RlbAIAAAAJBgAAAA0DAQYAAAABAAAABgcAAAAKTue6p+iKgueCuQoKCgkIAAAACgEIAAAABAAAAAkJAAAAAQAAAAEAAAAHCQAAAAABAAAABAAAAAQSQ29kZS5DaGlsZHJlbk1vZGVsAgAAAAkKAAAADQMBCgAAAAEAAAAGCwAAAAbmspDlhYkGDAAAACBFMTBBREMzOTQ5QkE1OUFCQkU1NkUwNTdGMjBGODgzRQgIGQAAAAgN61IBVNY+04gKCAEBCw==";
       

        /// <summary>
        /// 反序列化 JSON
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            byte[] jsonBytes = null;

            for (int i = 0; i < 20; i++)
            {
                GC.Collect();
                Console.WriteLine("////////////////////////////////////////////////////////////");
                Console.WriteLine("////////////////反序列化回车开始测试" + (i + 1) + "////////////////////////");
                Console.WriteLine("////////////////////////////////////////////////////////////");
                Console.ReadLine();

                Console.WriteLine("//NET系统类 反序列化 实体类");
                DataContractModelJson<ChildrenModel>(jsonStr);

                Console.WriteLine("//优化NET系统类 反序列化 实体类");
                DataContractModelJsonSpeed<ChildrenModel>(jsonStr);

                Console.WriteLine("------------------------------------" + Environment.NewLine);

                Console.WriteLine("//NET WebJavaScript系统类 反序列化 实体类");
                WebJavaScriptModelJsonSpeed<ChildrenModel>(JavaScriptJson);

                Console.WriteLine("//NET Web JavaScript系统类 反序列化 JavaScriptObject");
                WebJavaScriptModelJsonSpeed<JavaScriptObject>(jsonStr);

                Console.WriteLine("//NET Web JavaScript系统类 反序列化 Dictionary");
                WebJavaScriptModelJsonSpeed<Dictionary<string, object>>(jsonStr);


                Console.WriteLine("------------------------------------" + Environment.NewLine);

                Console.WriteLine("Newtonsoft.Json 反序列化 实体类");
                NewtonsoftModelJson<ChildrenModel>(jsonStr);

                Console.WriteLine("Newtonsoft.Json 反序列化 JavaScriptObject");
                NewtonsoftModelJson<JavaScriptObject>(jsonStr);

                Console.WriteLine("Newtonsoft.Json 反序列化 实体类 Dictionary");
                NewtonsoftModelJson<Dictionary<string, object>>(jsonStr);

                Console.WriteLine("------------------------------------" + Environment.NewLine);

                Console.WriteLine("FluorineFx 反序列化 实体类");
                FluorineFxModelJson<ChildrenModel>(JavaScriptJson);

                Console.WriteLine("FluorineFx 反序列化 JavaScriptObject");
                FluorineFxDictionaryJson<JavaScriptObject>(jsonStr);

                Console.WriteLine("FluorineFx 反序列化 Dictionary");
                FluorineFxDictionaryJson<Dictionary<string, object>>(jsonStr);

                //Console.WriteLine("------------------------------------FluorineFx AMF3 2进制" + Environment.NewLine);

                //jsonBytes = Convert.FromBase64String(AMF3Base64Model);
                //Console.WriteLine("//FluorineFx AMF3 反序列化 Model ");
                //FluorineFxAMF3<ChildrenModel>(jsonBytes);

                //jsonBytes = Convert.FromBase64String(AMF3Base64);
                //Console.WriteLine("//FluorineFx AMF3 反序列化 Dictionary ");
                //FluorineFxAMF3<Dictionary<string, object>>(jsonBytes);

                //Console.WriteLine("------------------------------------BinaryFormatter 2进制" + Environment.NewLine);

                //jsonBytes = Convert.FromBase64String(BFBase64Model);
                //Console.WriteLine("//NET类库 BinaryFormatter 二进制 反序列化 实体类 ");
                //BinaryFormatterByte<ChildrenModel>(jsonBytes);

                //jsonBytes = Convert.FromBase64String(BFBase64);
                //Console.WriteLine("//NET类库 BinaryFormatter 二进制 反序列化 Dictionary ");
                //BinaryFormatterByte<Dictionary<string, object>>(jsonBytes);

                Console.ReadLine();
            }
        }
    }
}
